package com.it235.seata.business;

import com.it235.seata.business.client.OrderClient;
import com.it235.seata.business.client.StorageClient;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 功能描述:
 *
 * @author: 李明杰
 * @date: 2022/1/18 1:25
 */
@RestController
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class BusinessServiceApplication {
    @Resource
    private OrderClient orderClient;

    @Resource
    private StorageClient storageClient;

    public static void main(String[] args) {
        SpringApplication.run(BusinessServiceApplication.class, args);
    }

    @GetMapping("buy")
    @GlobalTransactional
    public String buy(long userId, long productId) {
        orderClient.create(userId, productId);
        storageClient.changeStorage(userId, 1);
        return "ok";

    }
}
